package com.xcf.controller.business.consignhandle;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.xcf.controller.base.BaseController;
import com.xcf.service.business.consign.CostModifyService;
import com.xcf.util.PageData;
@Controller
@RequestMapping(value="/costModify")
public class CostModifyController extends BaseController{
	@Autowired
	private CostModifyService costModifyService;
	@RequestMapping(value="/page")
	public ModelAndView costModifyPage()throws Exception{
		ModelAndView view = new ModelAndView();
		view.setViewName("/business/consignhandle/cost_modify_list");
		return view;
	}
	/**
	 * 固定费用写入费用表
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/consModifyInfo")
	public String consModifyInfo()throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();
		Float paymentAmount = null;
		if(!pd.getString("BUSINESS_TYPE_ID").isEmpty()){
			if(pd.getString("BUSINESS_TYPE_ID").equals("1")||pd.getString("BUSINESS_TYPE_ID").equals("2")){
				//海船公司固定附加费
				PageData botaCompany = costModifyService.findBoatCompanyFixedSurcharge(pd);
				if(botaCompany!=null){
				PageData saveBoatCompany  = new PageData();
				saveBoatCompany.put("TAX_PRICE", botaCompany.get("FEE_PRICE"));
				saveBoatCompany.put("COST_PLATE", "业务部门");
				saveBoatCompany.put("COST_NAME", "海船公司固定附加费");
				costModifyService.saveFeeInfo(saveBoatCompany);
				costModifyService.saveFeeCopeInfo(saveBoatCompany);
				PageData saveBoatCompanyTwo  = new PageData();
				saveBoatCompanyTwo.put("TAX_PRICE", Float.parseFloat(botaCompany.get("FEE_PRICE").toString()));
				saveBoatCompanyTwo.put("COST_PLATE", "船代板块");
				saveBoatCompanyTwo.put("COST_NAME", "海船公司固定附加费");
				costModifyService.saveFeeInfo(saveBoatCompanyTwo);
				costModifyService.saveFeeCopeInfo(saveBoatCompanyTwo);
				}
				//港口费用（外贸）
				pd.put("TRADE_TYPE", "外贸");
				PageData InterNalTradeFee = costModifyService.findInterNalTradeFee(pd);
				if(InterNalTradeFee!=null){
				PageData saveInterNalTradeFee  = new PageData();
				saveInterNalTradeFee.put("TAX_PRICE", InterNalTradeFee.get("UNIT_PRICE"));
				saveInterNalTradeFee.put("COST_PLATE", "业务部门");
				
				saveInterNalTradeFee.put("COST_NAME", "港口费用");
				costModifyService.saveFeeInfo(saveInterNalTradeFee);
				costModifyService.saveFeeCopeInfo(saveInterNalTradeFee);
				PageData saveInterNalTradeFee1 = new PageData();
				saveInterNalTradeFee1.put("TAX_PRICE", InterNalTradeFee.get("UNIT_PRICE"));
				saveInterNalTradeFee1.put("COST_PLATE", "船代板块");
				saveInterNalTradeFee1.put("COST_NAME", "港口费用");
				costModifyService.saveFeeInfo(saveInterNalTradeFee);
				costModifyService.saveFeeCopeInfo(saveInterNalTradeFee);
				}
				//CCA费用
				PageData CCAFee = costModifyService.findCCACost(pd);
				if(CCAFee!=null){
				PageData saveCCAFee  = new PageData();
				saveCCAFee.put("TAX_PRICE", CCAFee.get("UNIT_PRICE"));
				saveCCAFee.put("COST_PLATE", "业务部门");
				saveCCAFee.put("COST_NAME", "CCA费用");
				costModifyService.saveFeeInfo(saveCCAFee);
				costModifyService.saveFeeCopeInfo(saveCCAFee);
				PageData saveCCAFee1  = new PageData();
				saveCCAFee1.put("TAX_PRICE", CCAFee.get("UNIT_PRICE"));
				saveCCAFee1.put("COST_PLATE", "船代板块");
				saveCCAFee1.put("COST_NAME", "CCA费用");
				costModifyService.saveFeeInfo(saveCCAFee1);
				costModifyService.saveFeeCopeInfo(saveCCAFee1);
				}
			}else{
				//基础运价表
				PageData InternalTradeBase = costModifyService.findInternalTradeBase(pd);
				if(InternalTradeBase!=null){
				PageData saveInternalTradeBase  = new PageData();
				saveInternalTradeBase.put("TAX_PRICE", InternalTradeBase.get("UNIT_PRICE"));
				saveInternalTradeBase.put("COST_PLATE", "业务部门");
				saveInternalTradeBase.put("COST_NAME", "内贸基础运价费用");
				costModifyService.saveFeeInfo(saveInternalTradeBase);
				costModifyService.saveFeeCopeInfo(saveInternalTradeBase);
				PageData saveInternalTradeBase1  = new PageData();
				saveInternalTradeBase1.put("TAX_PRICE", InternalTradeBase.get("UNIT_PRICE"));
				saveInternalTradeBase1.put("COST_PLATE", "船代板块");
				saveInternalTradeBase1.put("COST_NAME", "内贸基础运价费用");
				costModifyService.saveFeeInfo(saveInternalTradeBase1);
				costModifyService.saveFeeCopeInfo(saveInternalTradeBase1);
				}
				//港口费用（内贸）
				pd.put("TRADE_TYPE", "内贸");
				PageData InterNalTradeFee = costModifyService.findInterNalTradeFee(pd);
				if(InterNalTradeFee!=null){
				PageData saveInterNalTradeFee  = new PageData();
				saveInterNalTradeFee.put("TAX_PRICE", InterNalTradeFee.get("UNIT_PRICE"));
				saveInterNalTradeFee.put("COST_PLATE", "业务部门");
				
				saveInterNalTradeFee.put("COST_NAME", "港口费用");
				costModifyService.saveFeeInfo(saveInterNalTradeFee);
				costModifyService.saveFeeCopeInfo(saveInterNalTradeFee);
				PageData saveInterNalTradeFee1 = new PageData();
				saveInterNalTradeFee1.put("TAX_PRICE", InterNalTradeFee.get("UNIT_PRICE"));
				saveInterNalTradeFee1.put("COST_PLATE", "船代板块");
				saveInterNalTradeFee1.put("COST_NAME", "港口费用");
				costModifyService.saveFeeInfo(saveInterNalTradeFee);
				costModifyService.saveFeeCopeInfo(saveInterNalTradeFee);
				}
			}
		}
		
		
		return null;
		
	}
}
